package com.aigou.admin.service.impl;

import com.aigou.admin.dao.ShopCartDao;
import com.aigou.admin.dao.impl.ShopCartDaoImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.ShopCart;
import com.aigou.admin.service.ShopCartService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author: xsc_hunter
 * @Date: 2024/12/4) 下午3:55
 * @Version: 1.0
 */

@Service
@AllArgsConstructor
public class ShopCartServiceImpl implements ShopCartService {
    private ShopCartDao shopCartDao;

    @Override
    public PageEntity<ShopCart> findShopCartByPage (Integer current, Integer pageSize) {
        int total = shopCartDao.selectCount();
        List<ShopCart> shopCartList = shopCartDao.selectShopCartByLimit((current - 1) * pageSize, pageSize);
        PageEntity<ShopCart> pageEntity = new PageEntity<>();
        pageEntity.setTotal(total);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(shopCartList);
        return pageEntity;
    }

    @Override
    public List<ShopCart> findAll() {
        return shopCartDao.selectAll();
    }

    @Override
    public ShopCart findById(String id) {
        return shopCartDao.selectById(id);
    }

    @Override
    public Boolean save(ShopCart shopCart) {
        return shopCartDao.insert(shopCart);
    }

    @Override
    public Boolean update(ShopCart shopCart) {
        return shopCartDao.update(shopCart);
    }

    @Override
    public Boolean remove(String id) {
        return shopCartDao.delete(id);
    }
}
